package com.solomiao.demo.multi.thread.demo12;

public class RunnableDemo12 implements Runnable {

    private int ticket;
    public RunnableDemo12(int ticket) {
        this.ticket = ticket;
    }

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            synchronized (RunnableDemo12.class) {
                if (ticket > 0) {
                    System.out.println("当前票数：" + ticket--);
                }
            }
        }
    }

    public int getTicket() {
        return ticket;
    }

}
